package ordena1;

import java.util.Random;

public class OrdenaImpl implements Ordena {

	public static final Random RND = new Random();
	
	public static final int QUICK = 1;
    public static final int MERGE = 2;
    public static final int SELECTION = 3;
    public static final int INSERTION = 4;
    public static final int BUBBLE = 5;
    
    
	public int[] gerarVetor(int tamanho) {
		if (tamanho > 1000){
			System.out.println("Coloque um numero menor que 1000");
			return null;
		} else{
			int[] vetor = new int[tamanho];
			for (int i = 0; i <= tamanho - 1; i++) {
				vetor[i] = RND.nextInt();
			}
			return vetor;
		}
	}

	public long ordena(int metodo, int[] vetor) {
		long tempo = 0; 
		long inicio = 0; 
		long fim = 0;
		
		if (metodo == QUICK){
			QuickSort qs = new QuickSort();
			inicio = System.currentTimeMillis();
			qs.sort(vetor);
			fim = System.currentTimeMillis();
		}else if(metodo == MERGE){
			MergeSort ms = new MergeSort();
			inicio = System.currentTimeMillis();
			ms.merge(0, vetor.length - 1, vetor);
			fim = System.currentTimeMillis();
		}else if(metodo == SELECTION){
			SelectionSort ss = new SelectionSort();
			inicio = System.currentTimeMillis();
			ss.selection(vetor);
			fim = System.currentTimeMillis();
		}else if(metodo == INSERTION){
			InsertionSort is = new InsertionSort();
			inicio = System.currentTimeMillis();
			is.insertion(vetor, 0);
			fim = System.currentTimeMillis();
		}else if(metodo == BUBBLE){
			BubbleSort bs = new BubbleSort();
			inicio = System.currentTimeMillis();
			bs.bubble(vetor);
			fim = System.currentTimeMillis();
		}
		
		tempo = fim - inicio;
		
		return tempo;
	}
	
	public static void main(String[] args) {


        Ordena ord = new OrdenaImpl();
       
        System.out.println("Para n=10\n");

        System.out.println(ord.ordena(Ordena.QUICK,ord.gerarVetor(10)));

        System.out.println(ord.ordena(Ordena.MERGE,ord.gerarVetor(10)));

        System.out.println(ord.ordena(Ordena.SELECTION,ord.gerarVetor(10)));

        System.out.println(ord.ordena(Ordena.INSERTION,ord.gerarVetor(10)));

        System.out.println(ord.ordena(Ordena.BUBBLE,ord.gerarVetor(10)));

       

        System.out.println("Para n=800\n");

        System.out.println(ord.ordena(Ordena.QUICK,ord.gerarVetor(800)));

        System.out.println(ord.ordena(Ordena.MERGE,ord.gerarVetor(800)));

        System.out.println(ord.ordena(Ordena.SELECTION,ord.gerarVetor(800)));

        System.out.println(ord.ordena(Ordena.INSERTION,ord.gerarVetor(800)));

        System.out.println(ord.ordena(Ordena.BUBBLE,ord.gerarVetor(800)));
    }


}
